Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Basic »
  • String »

Table of Contents

Python v3.7 HowTos:

  • ----------------
  • Recursion
  • Backtracking
  • Dynamic Programming
  • Greedy
  • Sort
  • Binary Search
  • Depth First Search [DFS]
  • Breadth First Search [BFS]
  • Binary Search Tree [BST]
  • ----------------
  • Array
  • String
  • Heap
  • Stack
  • Queue
  • Tree
  • Linked List
  • Hash Table
  • Bit Manipulation
  • Two Pointers
  • Math
  • Decorator
  • ----------------
  • Basic
  • Intermediate
  • Advanced
  • Interview
  • ----------------
  • Spark
  • Tkinter
  • Turtle
  • Games
  • Web
  • ----------------
  • About
  • History

Previous topic

Print floating numbers upto 2 decimal places with sign

Next topic

Print integers with zeros on the left

Quick search

Print floating numbers with no decimal placesΒΆ

Print the following floating numbers with no decimal places.
x = 3.1415926
y = -12.9999

print("\nOriginal Number: ", x)
print("Formatted Number with no decimal places: "+"{:.0f}".format(x));
print("Original Number: ", y)
print("Formatted Number with no decimal places: "+"{:.0f}".format(y));

Output:

Original Number:  3.1415926
Formatted Number with no decimal places: 3
Original Number:  -12.9999
Formatted Number with no decimal places: -13

See also

https://www.w3resource.com/python-exercises/string/python-data-type-string-exercise-32.php

Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Basic »
  • String »
© Copyright 2020, Sergiy Zaytsev, szaytsev@hotmail.com. Created using Sphinx 2.3.0.